package com.xioyi.news.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.xioyi.news.domain.Account;
import com.xioyi.news.form.UserForm;
import com.xioyi.news.service.impl.AccountService;

public class LoginAction extends DispatchAction {

	private AccountService accountService;
	
	public ActionForward doLogin(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		UserForm userForm=(UserForm) form;
		System.out.println(userForm.getUsername());
		request.getSession().setAttribute("User", userForm);
		Account account=null;
		if(accountService!=null){
			account=accountService.findAccount(1);
		}
		request.getSession().setAttribute("User", account);
		System.out.println("doLogin:exec");
		return mapping.findForward("successed");
	}

	/**
	 * @return the accountService
	 */
	public AccountService getAccountService() {
		return accountService;
	}

	/**
	 * @param accountService the accountService to set
	 */
	public void setAccountService(AccountService accountService) {
		this.accountService = accountService;
	}

	
	
}
